package com.abl.common.util;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.text.MessageFormat;

@Slf4j
public class SystemKit {

    public static String getOsName() {
        return System.getProperty("os.name");
    }

    public static boolean isWindows() {
        return getOsName().contains("Windows");
    }

    public static boolean isMac() {
        return getOsName().contains("Mac");
    }

    public static boolean isSolaris() {
        return getOsName().contains("Solaris");
    }

    public static boolean isUnix() {
        return getOsName().contains("Unix");
    }

    /**
     * 打开指定输出文件目录
     *
     * @param outDir 输出文件目录
     * @throws IOException
     */
    public static void openDir(String outDir) throws IOException {
        if (isMac()) {
            Runtime.getRuntime().exec("open " + outDir);
        }
        if (isWindows()) {
            Runtime.getRuntime().exec(MessageFormat.format("cmd /c start \"\" \"{0}\"", outDir));
        }
        log.debug("文件输出目录:{}", outDir);
    }

}
